
package guda.house.biz.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * Created by well on 15/6/8.
 */

public class SmsUtil {

    private static Logger log = LoggerFactory.getLogger(SmsUtil.class);


    private static String BASE_URI = "http://yunpian.com";


    private static String VERSION = "v1";


    private static String ENCODING = "UTF-8";


    private static String URI_GET_USER_INFO = BASE_URI + "/" + VERSION + "/user/get.json";

    private static String URI_SEND_SMS = BASE_URI + "/" + VERSION + "/sms/send.json";


    private static String URI_TPL_SEND_SMS = BASE_URI + "/" + VERSION + "/sms/tpl_send.json";


    public static String sendSms(String apikey, String text, String mobile) throws IOException {

        return null;
    }


    public static String sendSmsCode(String mobile, String code) {
        try {
            String apikey = "fd1aaa6aa2525c0c7e7da52cb11196f1";

            String msg = "【乐享优家】您的验证码是" + code + "。如非本人操作，请忽略本短信";
            return SmsUtil.sendSms(apikey, msg, mobile);
        } catch (IOException e) {
            return "";
        }

    }

    public static String sendSms(String mobile, String text) {
        try {
            String apikey = "fd1aaa6aa2525c0c7e7da52cb11196f1";

            String msg = "【乐享优家】" + text;
            return SmsUtil.sendSms(apikey, msg, mobile);
        } catch (IOException e) {
            return "";
        }

    }


    public static String filterNull(String str) {
        if (str == null) {
            return "无";
        }
        return str;
    }


    public static String randomFourNum() {
        Random random = new Random();
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < 4; i++) {
            result.append(random.nextInt(10));
        }
        return result.toString();
    }


    public static boolean isMobileNO(String mobiles) {
        if (mobiles == null) {
            return false;
        }
        Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(14[57])|(17[0])|(18[0,0-9]))\\d{8}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    public static void main(String[] args) throws IOException {
        System.out.println(isMobileNO("15824101179"));
    }
}

